<?php
class ControllerReportProductPurchased extends AdminController {
	public function index() {

		$this->document->setTitle($this->_['heading_title']);

		$qf = new Query_filter();

		M('report/product');

		$this->data['products'] = array();

		$product_total = $this->model_report_product->getTotalPurchased($qf);

		$results = $this->model_report_product->getPurchased($qf);

		foreach ($results as $result) {
			$this->data['products'][] = array(
				'name'       => $result['name'],
				'model'      => $result['model'],
				'quantity'   => $result['quantity'],
				'total'      => $this->currency->format($result['total'], C('config_currency'))
			);
		}


		$this->data['order_statuses'] = C('cache_order_status');

		$this->data['pagination'] = $this->pagination($product_total)->render();

		$this->data['filter_date_start'] = $qf->get('filter_date_start', '');
		$this->data['filter_date_end'] = $qf->get('filter_date_end', '');
		$this->data['filter_order_status_id'] = $qf->get('filter_order_status_id', 0);

		$this->display('report/product_purchased.tpl');
	}
}
?>